﻿using System;
using System.Globalization;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SoftwareApproach.TestingExtensions
{
    internal static class AssertHelper
    {
        internal static void HandleFail(string assertionName, string message, params object[] parameters)
        {
            Type t = typeof(Assert);
            MethodInfo mi = t.GetMethod("HandleFail", BindingFlags.Static | BindingFlags.NonPublic);
            try
            {
                mi.Invoke(null, new object[] { assertionName, message, parameters });
            }
            catch (TargetInvocationException ex)
            {
                throw ex.InnerException;
            }
        }

        internal static string AppendMessage(this string source, string message, params object[] parameters)
        {
            string messageString = String.Format(CultureInfo.CurrentCulture, message, parameters);
            return String.Format(CultureInfo.CurrentCulture, "{0} {1}", messageString, source);
        }
    }
}
